home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Go Sit In The Corner 1.0 / source / init code / init.c next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.4 KB  |  149 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        init.c
  4.  
  5. Purpose:    This module handles INIT initialization & installation of
  6.             the VBL.
  7.  
  8.  
  9. Go Sit In The Corner -=- not you, just the cursor
  10. Copyright ©1994, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "structs.h"
  30. #include "init.h"
  31. #include "prefs.h"
  32. #include "really notify.h"
  33. #include "SetUpA4.h"
  34. #include "Retrace.h"
  35.  
  36. void main(void)
  37. {
  38.     int                resultCode;
  39.     PrefHandle        cdevStorage;
  40.     Boolean            goon;
  41.     
  42.     RememberA0();
  43.     SetUpA4();
  44.     
  45.     goon=TRUE;
  46.     
  47.     cdevStorage=NewHandle(sizeof(PrefStruct));
  48.     if (cdevStorage==0L)
  49.     {
  50.         StartupError(kNoMemory);
  51.         RestoreA4();
  52.         return;
  53.     }
  54.     
  55.     if (goon)
  56.     {
  57.         resultCode=PreferencesInit(cdevStorage);
  58.         if ((resultCode!=prefs_allsWell) && (resultCode!=prefs_virginErr))
  59.         {
  60.             StartupError(resultCode);
  61.             goon=FALSE;
  62.         }
  63.     }
  64.     
  65.     if (goon)
  66.     {
  67.         if ((**cdevStorage).isOn)
  68.         {
  69.             resultCode=InstallTheVBL(cdevStorage);
  70.             if (resultCode!=allsWell)
  71.             {
  72.                 StartupError(resultCode);
  73.                 goon=FALSE;
  74.             }
  75.         }
  76.     }
  77.     
  78.     SaveThePrefs(cdevStorage);
  79.     
  80.     if (goon)
  81.         StartupGood(cdevStorage);
  82.     
  83.     DisposeHandle(cdevStorage);
  84.     RestoreA4();
  85. }
  86.  
  87. int InstallTheVBL(PrefHandle cdevStorage)
  88. {
  89.     Ptr                tempPtr;
  90.     VBLTask            *vblPtr;
  91.     Handle            ourCode;
  92.     Rect            mainRect;
  93.     
  94.     GetMainScreenBounds(&mainRect);
  95.     ourCode=0L;
  96.     ourCode=GetResource('vbl ', 999);
  97.     if (ourCode!=0L)
  98.     {
  99.         if (*ourCode==0L)
  100.             LoadResource(ourCode);
  101.         if (*ourCode==0L)
  102.             return kCantGetResource;
  103.         
  104.         HLock(ourCode);
  105.         DetachResource(ourCode);
  106.         
  107.         tempPtr=NewPtrSys(12+sizeof(VBLTask));
  108.         *((unsigned char*)tempPtr)=(**cdevStorage).always;
  109.         *((unsigned long*)((long)tempPtr+4))=(**cdevStorage).numTicks;
  110.         *((int*)((long)tempPtr+8))=(((**cdevStorage).whichCorner==0x00) ||
  111.             ((**cdevStorage).whichCorner==0x03)) ? mainRect.left : mainRect.right;
  112.         *((int*)((long)tempPtr+10))=(((**cdevStorage).whichCorner==0x00) ||
  113.             ((**cdevStorage).whichCorner==0x01)) ? mainRect.top : mainRect.bottom;
  114.         
  115.         vblPtr = (VBLTask*) ((long)tempPtr+12);
  116.         vblPtr->qType = vType;
  117.         vblPtr->vblAddr = (ProcPtr) *ourCode;
  118.         vblPtr->vblCount = 1;
  119.         vblPtr->vblPhase = 0;
  120.         VInstall(vblPtr);
  121.         (**cdevStorage).ourCodePtr=(unsigned long)ourCode;
  122.         (**cdevStorage).ourVBLPtr=(unsigned long)tempPtr;
  123.     }
  124.     else return kCantGetResource;
  125.  
  126.     return prefs_allsWell;
  127. }
  128.  
  129. void GetMainScreenBounds(Rect* theRect)
  130. {
  131.     long                oldA5;
  132.     QDGlobals            qd;
  133.     GrafPort            gp;
  134.     GrafPtr                savePort;
  135.  
  136.     GetPort(&savePort);
  137.     oldA5 = SetA5((long)&qd.end);
  138.     InitGraf(&qd.thePort);
  139.     OpenPort(&gp);
  140.     SetCursor(&qd.arrow);
  141.     
  142.     SetRect(theRect, qd.screenBits.bounds.left, qd.screenBits.bounds.top,
  143.         qd.screenBits.bounds.right, qd.screenBits.bounds.bottom);
  144.     
  145.     ClosePort(&gp);
  146.     SetA5(oldA5);
  147.     SetPort(savePort);
  148. }
  149.